package com.example.guidepage;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class GuideActivity extends AppCompatActivity {

    private ViewPager guidePage;

    private GuidePageAdapter guidePageAdapter;

    private Button skipButton;

    private RadioGroup radioGroup;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guide);

        radioGroup = findViewById(R.id.radioGroup_dots);

        skipButton = findViewById(R.id.button_skip);
        View.OnClickListener clickStartListener = (v) -> {
            Toast.makeText(this, "跳转", Toast.LENGTH_SHORT).show();
            startActivity(new Intent(this, MainActivity.class));
        };
        skipButton.setOnClickListener(clickStartListener);

        guidePage = findViewById(R.id.viewPager);

        guidePageAdapter = new GuidePageAdapter(this, clickStartListener);
        guidePage.setAdapter(guidePageAdapter);
        guidePage.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

            /*@Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                super.onPageScrolled(position, positionOffset, positionOffsetPixels);
            }

            @Override
            public void onPageScrollStateChanged(int state) {
                super.onPageScrollStateChanged(state);
            }*/

            // ViewPager的页面改变触发
            @Override
            public void onPageSelected(int position) {
                RadioButton radioButton = (RadioButton) radioGroup.getChildAt(position);
                if (radioButton != null) {
                    radioButton.setChecked(true);
                }
            }
        });

        // 设置显示哪一页，默认第一页，true是动画
//        guidePage.setCurrentItem(0, true);
    }


}